package lambda.function;

import lambda.entity.User;

import java.util.function.Function;

/**
 * @author LIBOFEI
 * @ClassName FunctionTest
 * @description Function<T,R> 函数型接口 对类型为 T 的对象进行操作返回 R 类型的对象
 * @date 2022/4/6 17:05
 * @Version 1.0
 **/
public class FunctionTest {

    public static void main(String[] args) {
        //未使用lamda表达式
        Integer integer = integer(new Function<User, Integer>() {
            @Override
            public Integer apply(User user) {
                Integer length = user.getName().length();
                return length;
            }
        });
        System.out.println(integer);


        Integer integer1 = integer(user -> {
            return user.getName().length();
        });
        System.out.println(integer1);

        Integer integer2 = integer(user -> user.getName().length());
        System.out.println(integer2);

        Integer integer3 = integer(User::getId);
        System.out.println(integer3);
    }


    public static Integer integer(Function<User,Integer> userIntegerFunction){
        User user = new User();
        user.setId(12);
        user.setName("你是我这一生想要的美丽女人");
        Integer apply = userIntegerFunction.apply(user);
        return apply;
    }
}
